package com.gitee.huxing.course.conc.task;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool14 extends AbstractTaskThreadPool{

    public static AtomicInteger atomicInteger = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool14().task();
    }

    @Override
    public int threadTask() {
        // 线程池处理
        ExecutorService service = Executors.newFixedThreadPool(1);
        service.submit(() -> atomicInteger.set(CourseTask.sum()), atomicInteger);
        service.shutdown();
        try {
            service.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
        } catch (InterruptedException ex){
            ex.printStackTrace();
        }
        return atomicInteger.get();
    }
}
